package com.jzj.singleton.demo8;


import java.lang.reflect.Constructor;

/**
 * @Author Jzj
 * @Date 2021/12/30 17:41
 * @Version 1.0
 * 破坏单例设计模式：反射
 */
public class Client {
    public static void main(String[] args) throws Exception {
        //获取Singleton的字节码对象
        Class clazz = Singleton.class;
        //获取无参构造方法对象
        Constructor cons = clazz.getDeclaredConstructor();
        //取消访问检查
        cons.setAccessible(true);
        //创建Singleton对象
        Singleton s1 = (Singleton)cons.newInstance();
        Singleton s2 = (Singleton)cons.newInstance();

        System.out.println(s1 == s2);

    }
}
